#! /bin/sh

source /etc/rc.d/common

SNMPTRAPD="/usr/sbin/snmptrapd"
SNMPTRAPD_LOCK="/var/lock/snmptrapd"
DFLT_OPTS="-Lsd -p /var/run/snmptrapd.pid > /dev/null 2>&1"

check_args ${@}

SCRIPT="$(/usr/bin/basename ${0})"
if check_opts_set ${SCRIPT}; then
    USER_OPTS="$(get_rc_opts ${SCRIPT})"
    if [ ${?} -ne 0 ]; then
        /bin/echo ${USER_OPTS}
        exit 1
    fi
else
    USER_OPTS="${DFLT_OPTS}"
fi

start() {
    /bin/echo "Starting snmptrapd..."
    eval ${SNMPTRAPD} ${USER_OPTS} || exit 1
    /bin/touch ${SNMPTRAPD_LOCK}
}

stop() {
    /bin/echo "Stopping snmptrapd..."
    /bin/kill -TERM $(/bin/pidof ${SNMPTRAPD}) || exit 1
    wait_for_stop ${SNMPTRAPD} && /bin/rm -f ${SNMPTRAPD_LOCK}
}

status() {
    /bin/pidof ${SNMPTRAPD} > /dev/null 2>&1
    exit ${?}
}

# Perform specified action
${1}
